#include "material/particlematerial.h"


CParticleMaterial::CParticleMaterial() :
CMaterial(){

}
CParticleMaterial::~CParticleMaterial(){

}
void CParticleMaterial::Init(){
    CMaterial::Init();

//https://github.com/opengl-tutorials/ogl/blob/master/tutorial18_billboards_and_particles/Particle.vertexshader
////    const char* _strVertexShader = "\
/////*#ifdef __HIGHTP__*/ \n\
////    precision highp float; \n\
/////*#endif*/ \n\
////uniform mat4 projectionViewMatrix;\
////uniform mat4 viewMatrix;\
////attribute vec3 a_position;\
////attribute vec3 a_normal0; \
////attribute vec2 a_texcoord0;\
////varying vec2 vUv;\
////void main(){\
////    vec3 CameraRight_worldspace = vec3(viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0]);\
////    vec3 CameraUp_worldspace = vec3( viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1] );\
////    float particleSize = a_normal0.z;\
////    vec3 particleCenter_wordspace = a_position;\
////    vec3 vertexPosition_worldspace = particleCenter_wordspace + CameraRight_worldspace * a_normal0.x * particleSize + CameraUp_worldspace * a_normal0.y * particleSize; \
////    gl_Position = projectionViewMatrix * vec4( vertexPosition_worldspace, 1.0f ); \
////    vUv = a_texcoord0;\
////}";
    const char* _strVertexShader = "\
/*#ifdef __HIGHTP__*/ \n\
    precision highp float; \n\
/*#endif*/ \n\
uniform mat4 projectionViewMatrix;\
uniform mat4 viewMatrix;\
uniform float billboardMode;\
attribute vec3 a_position;\
attribute vec4 a_color0; \
attribute vec2 a_texcoord0;\
varying vec4 vColor;\
varying vec2 vUv;\
void main(){\
mat4 rotationMatrix = mat4(\
    1.0, 0.0, 0.0,0.0,\
    0.0, 5.96046448e-08, -0.999999940,0.0,\
    0.0, 0.999999940, 5.96046448e-08,0.0,\
    0.0, 0.0, 0.0,1.0\
);\
    gl_Position = projectionViewMatrix * vec4( a_position, 1.0f ); \
    vColor = a_color0;\
    vUv = a_texcoord0;\
}";

    const char* _strFragmentShader =
        "                                \
/*#ifdef __HIGHTP__*/ \n\
    precision highp float; \n\
/*#endif*/ \n\
uniform sampler2D diffuseMap; \
varying vec4 vColor;\
varying vec2 vUv; \
void main() {\
    vec4 _color = texture2D(diffuseMap, vUv); \
    if( _color.a < 0.01 )discard;\
    gl_FragColor = _color * vColor; \
}";

    m_hMaterialHandle = Material_Create( "ParticleMaterial", (byte*)_strVertexShader, strlen( _strVertexShader ), (byte*)_strFragmentShader, strlen( _strFragmentShader ) );
    m_hProjectionViewMatrixHandle = Material_GetUniform( m_hMaterialHandle, "projectionViewMatrix", EUT_MATRIX44 );
    m_hViewMatrixHandle = Material_GetUniform( m_hMaterialHandle, "viewMatrix", EUT_MATRIX44 );
    m_hDiffuseMapHandle = Material_GetUniform( m_hMaterialHandle, "diffuseMap", EUT_SAMPLER );
    m_hBillboardModeHandle = Material_GetUniform( m_hMaterialHandle, "billboardMode", EUT_FLOAT );
    m_hDiffuseHandle = Material_GetUniform( m_hMaterialHandle, "diffuse", EUT_VEC4 );
}
void CParticleMaterial::SetBillboardMode( int32 nType ){

}
//
//
///////////////////////////////////////////////////////////////////////////////////////////
//CRibbonMaterial::CRibbonMaterial():
//CMaterial(){
//
//}
//CRibbonMaterial::~CRibbonMaterial(){
//
//}
//void CRibbonMaterial::Init(){
//    CMaterial::Init();
//
////https://github.com/opengl-tutorials/ogl/blob/master/tutorial18_billboards_and_particles/Particle.vertexshader
//    const char* _strVertexShader = "\
///*#ifdef __HIGHTP__*/ \n\
//    precision highp float; \n\
///*#endif*/ \n\
//uniform mat4 projectionViewMatrix;\
//attribute vec3 a_position;\
//attribute vec2 a_texcoord0;\
//varying vec2 vUv;\
//void main(){\
//    gl_Position = projectionViewMatrix * vec4( a_position, 1.0 ); \
//    vUv = a_texcoord0;\
//}";
//
//    const char* _strFragmentShader =
//        "                                \
///*#ifdef __HIGHTP__*/ \n\
//    precision highp float; \n\
///*#endif*/ \n\
//uniform sampler2D diffuseMap; \
//uniform vec4 diffuse; \
//varying vec2 vUv; \
//void main() {\
//    vec4 _color = texture2D(diffuseMap, vUv); \
//    gl_FragColor = _color * diffuse; \
//}";
//
//    m_hMaterialHandle = Material_Create( "RibbonMaterial", (byte*)_strVertexShader, strlen( _strVertexShader ), (byte*)_strFragmentShader, strlen( _strFragmentShader ) );
//    m_hProjectionViewMatrixHandle = Material_GetUniform( m_hMaterialHandle, "projectionViewMatrix", EUT_MATRIX44 );
//    //m_hViewMatrixHandle = Material_GetUniform( m_hMaterialHandle, "viewMatrix", EUT_MATRIX44 );
//    m_hDiffuseMapHandle = Material_GetUniform( m_hMaterialHandle, "diffuseMap", EUT_SAMPLER );
//    m_hDiffuseHandle = Material_GetUniform( m_hMaterialHandle, "diffuse", EUT_VEC4 );
//
//}

